namespace MeetingManagement.Domain.ValueObjects
{
    public class TimeSlot
    {
        public DateTime Start { get; private set; }
        public DateTime End { get; private set; }
        public TimeSpan Duration => End - Start;

        private TimeSlot() { }

        public static TimeSlot Create(DateTime start, DateTime end)
        {
            if (start >= end)
                throw new ArgumentException("End time must be after start time");

            return new TimeSlot
            {
                Start = start,
                End = end
            };
        }

        public bool Overlaps(TimeSlot other)
        {
            return (Start < other.End && End > other.Start);
        }

        public bool Contains(DateTime dateTime)
        {
            return dateTime >= Start && dateTime <= End;
        }

        public override bool Equals(object obj)
        {
            if (obj is not TimeSlot other)
                return false;

            return Start == other.Start && End == other.End;
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(Start, End);
        }
    }
}
